package com.sugar.queryinfo.module.business.controller.admin.dataquerynomraltype;

import com.sugar.queryinfo.framework.idempotent.core.annotation.Idempotent;
import com.sugar.queryinfo.framework.idempotent.core.keyresolver.impl.UserIdempotentKeyResolver;
import com.sugar.queryinfo.framework.security.core.util.SecurityFrameworkUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.queryinfo.framework.common.pojo.PageParam;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.pojo.CommonResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;
import static com.sugar.queryinfo.framework.common.pojo.CommonResult.success;

import com.sugar.queryinfo.framework.excel.core.util.ExcelUtils;

import com.sugar.queryinfo.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.queryinfo.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.queryinfo.module.business.controller.admin.dataquerynomraltype.vo.*;
import com.sugar.queryinfo.module.business.dal.dataobject.dataquerynomraltype.DataQueryNomralTypeDO;
import com.sugar.queryinfo.module.business.service.dataquerynomraltype.DataQueryNomralTypeService;

@Tag(name = "管理后台 - 数据查询默认类型")
@RestController
@RequestMapping("/business/data-query-nomral-type")
@Validated
public class DataQueryNomralTypeController {

    @Resource
    private DataQueryNomralTypeService dataQueryNomralTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建数据查询默认类型")
    @Idempotent(timeout = 3, message = "您的手速太快啦！", keyResolver = UserIdempotentKeyResolver.class)
    public CommonResult<Long> createDataQueryNomralType(@Valid @RequestBody DataQueryNomralTypeSaveReqVO createReqVO) {
        return success(dataQueryNomralTypeService.createDataQueryNomralType(createReqVO, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/get")
    @Operation(summary = "获得数据查询默认类型")
    public CommonResult<List<String>> getDataQueryNomralType() {
        DataQueryNomralTypeDO dataQueryNomralType = dataQueryNomralTypeService.getDataQueryNomralType(SecurityFrameworkUtils.getLoginUserId());
        if (dataQueryNomralType == null) {
            return success(Collections.emptyList());
        }
        return success(dataQueryNomralType.getTypeCode());
    }
}